﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Model;
using BLL;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace WebApplication1.Controllers
{
    public class RegardController : ApiController
    {
        /// <summary>
        /// 获取我收藏的文章
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string GetRegard(int Uid, int PageIndex, int PageSize)
        {
            //实例化对象
            RegardBLL bll = new RegardBLL();
            PageList<RegardModel> list = bll.GetRegard(Uid,PageIndex, PageSize);
            string Json = JsonConvert.SerializeObject(list, new DataSetConverter());
            return Json;
        }
        [HttpGet]
        /// <summary>
        /// 显示文章详细信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public string  GetRegardId(int Uid, int Id)
        {
            //实例化对象
            RegardBLL bll = new RegardBLL();
            RegardModel list = bll.GetRegardId(Uid, Id);
            string Json = JsonConvert.SerializeObject(list, new DataSetConverter());
            return Json;
        }
        /// <summary>
        /// 获取文章
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public string GetRegardALL(int PageIndex, int PageSize)
        {
            //实例化对象
            RegardBLL bll = new RegardBLL();
            PageList<RegardModel> list = bll.GetRegardALL(PageIndex,PageSize);
            string Json = JsonConvert.SerializeObject(list, new DataSetConverter());
            return Json;
        }
        [HttpGet]
        /// <summary>
        /// 显示文章详细信息
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public string GetRegardIdAll(int Id)
        {
            //实例化对象
            RegardBLL bll = new RegardBLL();
            RegardModel list = bll.GetRegardIdAll(Id);
            string Json = JsonConvert.SerializeObject(list, new DataSetConverter());
            return Json;
        }
        [HttpGet]
        /// <summary>
        /// 判断文章是否已经收藏
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public int AddRegard(int Login_Id, int Id)
        { 
            //实例化对象
            RegardBLL bll = new RegardBLL();
            if (bll.AddRegard(Login_Id,Id) > 0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        [HttpGet]
        /// <summary>
        /// 收藏
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public int AddRegardDo(int Login_Id, int Id)
        {
            //实例化对象
            RegardBLL bll = new RegardBLL();
            if (bll.AddRegardDo(Login_Id,Id) > 0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
        [HttpGet]
        /// <summary>
        /// 收藏文章伪删除
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public int Del(int Login_Id, int Id)
        {
            //实例化对象
            RegardBLL bll = new RegardBLL();
            if (bll.Del(Login_Id, Id) > 0)
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }
    }
}
